package ma.ensao.egicom.dao.implementations;

import java.util.List;

import ma.ensao.egicom.core.model.Marketorder;
import ma.ensao.egicom.dao.interfaces.MarketorderDAO;

import org.hibernate.Query;
import org.scub.foundation.framework.core.dao.implementations.HibernateDaoBaseImplementation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MarketorderDAOImpl extends HibernateDaoBaseImplementation implements MarketorderDAO {

    private static final Logger log = LoggerFactory.getLogger(MarketorderDAO.class);

    // property constants
    public static final String ID = "id";

    public static final String DELIVRYADR = "delivryadr";

    public static final String FACTUREADR = "factureadr";

    /**
     * {@inheritDoc}
     */
    @Override
    public void save(Marketorder transientInstance) {
        save(transientInstance);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void delete(Marketorder persistentInstance) {
        delete(persistentInstance);

    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Marketorder findById(java.lang.Integer id) {
        return load(id, Marketorder.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List findByProperty(String propertyName, Object value) {
        log.debug("finding Marketorder instance with property: " + propertyName + ", value: " + value);
        try {
            String queryString = "from Marketorder as model where model." + propertyName + "= ?";
            Query queryObject = createQuery(queryString);
            queryObject.setParameter(0, value);
            return queryObject.list();
        } catch (RuntimeException re) {
            log.error("find by property name failed", re);
            throw re;
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List findByDelivryadr(Object delivryadr) {
        return findByProperty(DELIVRYADR, delivryadr);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List findByFactureadr(Object factureadr) {
        return findByProperty(FACTUREADR, factureadr);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List findAll() {
        return loadAll(Marketorder.class);
    }

}
